﻿using Sustainalytics.ESG.Entities;
using Sustainalytics.Synchronization.Validation.ValidationRules.Comprehensive;
using System.Collections;
using System.Collections.Generic;
using Xunit;

namespace Sustainalytics.Synchronization.Validation.Tests
{
    [Trait("Category", "Unit")]
    public class RelativePositionChangeTest
    {
        private readonly RelativePositionChangeRule _sut;

        public RelativePositionChangeTest()
        {
            this._sut = new RelativePositionChangeRule();
        }

        [Theory, ClassData(typeof(RelativePositionInput))]
        public void Given_relative_position_should_return_false_when_position_changed_three_levels_or_more(RPCompanyESGComputationResult fakeValidated, RPCompanyESGComputationResult fakeReference, bool expected)
        {
            var actual = _sut.IsValid(fakeValidated, fakeReference);
            Assert.Equal(expected, actual);
        }

        public class RelativePositionInput : IEnumerable<object[]>
        {
            private readonly List<object[]> _data = new List<object[]>()
            {
                new object[]
                {
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 1 } } },
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 2 } } },
                    true
                },
                new object[]
                {
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 2 } } },
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 1 } } },
                    true
                },
                new object[]
                {
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 1 } } },
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 3 } } },
                    false
                },
                new object[]
                {
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 1 } } },
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 4 } } },
                    false
                },
                    new object[]
                {
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 3 } } },
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 1 } } },
                    false
                },
                new object[]
                {
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 4 } } },
                    new RPCompanyESGComputationResult { OverallPerformance = new RPPerformance { Assessment = new RPAssessment { Id = 1 } } },
                    false
                },
            };

            public IEnumerator<object[]> GetEnumerator()
            {
                return _data.GetEnumerator();
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }
        }
    }
}
